package com.weiaibenpao.demo.chislim.ui.activity.running;

import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.weiaibenpao.demo.chislim.R;
import com.weiaibenpao.demo.chislim.base.BaseActivity;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.OnClick;


public class SetDistanceActivity extends BaseActivity {

    @BindView(R.id.et_set_distance)
    EditText etSetDistance;

    @Override
    public int setLayoutResourceID() {
        return R.layout.activity_set_distance;
    }

    @Override
    public void init(Bundle savedInstanceState) {
        Typeface typeFace = Typeface.createFromAsset(getAssets(), "fonts/Reducto Condensed SSi Condensed.ttf");
        etSetDistance.setTypeface(typeFace);
        etSetDistance.requestFocus();


    }

    public static void openActivity(Context context) {
        Intent intent = new Intent(context, SetDistanceActivity.class);
        context.startActivity(intent);
    }

    @OnClick({R.id.left_image, R.id.right_text})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.left_image:
                finish();
                break;
            case R.id.right_text:
                commitDistance();

                break;
        }
    }

    private void commitDistance() {
        String s = etSetDistance.getText().toString();
        if (!TextUtils.isEmpty(s)) {
            float v = Float.parseFloat(s);
            if (v > 99.99f || v < 0.1) {
                Toast.makeText(SetDistanceActivity.this, "设定距离必须在0.1~99.99之间", Toast.LENGTH_SHORT).show();
            } else {
                EventBus.getDefault().post(s);
                finish();
            }
        } else
            Toast.makeText(SetDistanceActivity.this, "请设定“趣味跑”的距离", Toast.LENGTH_SHORT).show();


    }

}
